package io.renren.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.stereotype.Controller;

import io.renren.entity.DataAchievementEntity;
import io.renren.service.DataAchievementService;
import io.renren.utils.PageUtils;
import io.renren.utils.R;


/**
 * 业绩表
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-05-23 14:52:20
 */
@Controller
@RequestMapping("dataachievement")
public class DataAchievementController {
	@Autowired
	private DataAchievementService dataAchievementService;
	
	@RequestMapping("/dataachievement.html")
	public String list(){
		return "dataachievement/dataachievement.html";
	}
	
	/**
	 * 列表
	 */
	@ResponseBody
	@RequestMapping("/list")
	@RequiresPermissions("dataachievement:list")
	public R list(Integer page, Integer limit){
		Map<String, Object> map = new HashMap<>();
		map.put("offset", (page - 1) * limit);
		map.put("limit", limit);
		
		//查询列表数据
		List<DataAchievementEntity> dataAchievementList = dataAchievementService.queryList(map);
		int total = dataAchievementService.queryTotal(map);
		
		PageUtils pageUtil = new PageUtils(dataAchievementList, total, limit, page);
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@ResponseBody
	@RequestMapping("/info/{id}")
	@RequiresPermissions("dataachievement:info")
	public R info(@PathVariable("id") String id){
		DataAchievementEntity dataAchievement = dataAchievementService.queryObject(id);
		
		return R.ok().put("dataAchievement", dataAchievement);
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@RequestMapping("/save")
	@RequiresPermissions("dataachievement:save")
	public R save(@RequestBody DataAchievementEntity dataAchievement){
		dataAchievementService.save(dataAchievement);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("dataachievement:update")
	public R update(@RequestBody DataAchievementEntity dataAchievement){
		dataAchievementService.update(dataAchievement);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@ResponseBody
	@RequestMapping("/delete")
	@RequiresPermissions("dataachievement:delete")
	public R delete(@RequestBody String[] ids){
		dataAchievementService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
